<?php
class front_adminService extends commonService{
    private $table=null;
	private $founderid=null;
	
    public function __construct(){
        parent::__construct();
        $this->table=table('front_admin');
    }
	//批量更新arc status
	public function update_status($items,$d){
		$str=implode(',',$items);
		$this->m->query("update `{$this->table}` set `tag`=:d where `id` in ($str)",array('d'=>$d));
		return true;
	}
	//批量删除
	public function delete($items){
		$str=implode(',',$items);
		$this->m->query("delete from `{$this->table}` where `id` in ($str)");
		return true;
	}
    public function add_($post){
        $result=array();
        $vali=validate::check('front_admin',$post,'add');
        if($vali){
            $post['reg_time']=time();
            $post['login_time']=0;
            $post['login_ip']='';
            $post['times']=0;
            $post['myhash']=md5(rand(1000,9999));
    		$post['allow_del']=1;
    		$post['user_password']=md5password($post['user_password']);
            $result[0]=$this->model->_i($this->table,$post);
        }else{
            $result[0]=false;
            $result[1]="\\n".implode("\\n",validate::getMsg());
        }
        return $result;
    }
    //
	public function verify_pwd($user_id,$input_pwd){
		$query="select `user_password` from `{$this->table}` where `id`=:user_id limit 1";
		$pwd=$this->m->get_field($query,array('user_id'=>$user_id));
		return ($pwd==md5password($input_pwd));
	}
	public function judge($id){
		$query="select `allow_del` from `{$this->table}` where `id`=:id limit 1";
		$allow_del=$this->m->get_field($query,array('id'=>$id));
		if($allow_del=='1'){
			return true;
		}else{
			return false;
		}
	}
    //
    public function mod($id){
        $id=intval($id);
        if($id>0){
            return $this->model->_f($this->table,'*',$id);
        }
        return false;
    }
    public function mod_($post,$id){
        $result=array();
        $vali=validate::check('front_admin',$post,'mod',array('id::!='=>$id));
        if($vali){
    		if($post['user_password']!=''){
    			$post['user_password']=md5password($post['user_password']);
    		}else{
    			unset($post['user_password']);
    		}
    		$result[0]=$this->model->_u($this->table,$post,$id);
    	}else{
    		$result[0]=false;
            $result[1]="\\n".implode("\\n",validate::getMsg());
    	}
        return $result;
    }
    public function del($id){
        $id=intval($id);
        if($id>0){
            return $this->model->_d($this->table,$id);
        }
        return false;
    }
    public function li($condition,$extra='',$extra_data=array()){
        $return=array();
        $query="select * from `{$this->table}` where 1 {$extra} order by `id` asc";

        $p=new smart_pager(array($query,$extra_data),$this->m);
        //$p->address('&cat_id=%cat_id%','cat_id',100);
		foreach($condition as $k=>$v){
			$p->address("&{$k}=%{$k}%",$k,$v);
		}
        if($p->total_num>0){
            $return[]=$this->m->mselect($p->query,$extra_data);
            $return[]=$p;
        }
        return $return;
    }
}